<template>
  <div>
    <div class="title">
      <span class="active"><i>1</i>输入找回账号</span>
      <span><i>2</i>回答密保问题</span>
      <span><i>3</i>重置密码</span>
    </div>
    <div class="box">
      <div class="input-item">
        <label>请输入手机号：</label>
        <input type="text" v-model="phone" />
      </div>
      <button @click.prevent="next1">下一步</button>
    </div>
  </div>
</template>

<script>
import axios from "axios";
axios.defaults.baseURL = "http://124.223.14.236:3001/api";
export default {
  data() {
    return {
      phone: "",
    };
  },
  methods: {
    //点击下一步
    async next1() {
      if (this.phone.trim() === "") return alert("手机号不能为空");
      const { data } = await axios.get(`/user/findPwd/?phone=${this.phone}`);
      if (!data.success) return alert(data.msg);
      localStorage.setItem("id", JSON.stringify(data.data.id));
      //切换到第二步的组件
      this.$emit("change", "step2");
      //将请求回来的用户信息传递给父组件，再由父组件传递给第二步子组件
      this.$emit("set", data.data);
    },
  },
};
</script>

<style scoped>
@import url("@/assets/css/index.css");
</style>